package leetcode;

import java.util.Arrays;

public class MaxSubArray {
    public static void main(String[] args) {
        System.out.println((maxSubArray(new int[]{5,4,-1,7,8})));
    }
    public static int maxSubArray(int[] nums) {
        int max = nums[0];
        int pre = 0;
        for (int i =0; i < nums.length; i++) {
            pre = Math.max(pre + nums[i], nums[i]);
            max = Math.max(max, pre);
        }
        return max;
    }
}
